import os

Import('env lib lib_name libsuffix libgtest')

# get a list of source files
unittest_src = set()

CPPPATH = ['#include']

# for nicer looking commands (no -L.)
if env['GTEST_INCLUDE'] != '':
  CPPPATH.append(env['GTEST_INCLUDE'])
  
LIBPATH = ['#/lib']

if env['GTEST_LIB'] != '':
  LIBPATH.append(env['GTEST_LIB'])

prev_LIBS = env['LIBS']
LIBS = []
LIBS.extend(prev_LIBS)
LIBS.extend([lib_name, 'gtest', 'gtest_main'])

for f in env.Glob('*.cc'):
  path, file = os.path.split(str(f) )
  name, ext = os.path.splitext(file)
  
  unittest = env.Program(file,
              CPPPATH=CPPPATH,
              LIBPATH=LIBPATH,
              LIBS=LIBS)
  unittest_name = '%s%s%s' % (name, libsuffix, env['PROGSUFFIX'])
  
  depends = [lib]
  
  if libgtest:
    depends.append(libgtest)
    
  env.Depends(unittest, depends)
  env.InstallAs('#/bin/test/%s' % (unittest_name), unittest)